
import { FormItemRule } from 'element-plus'
import study from '../../../mysql_interface/studycodemodel'

interface Irules {
  type?: 'string' | 'number' | 'boolean' | 'method' | 'regexp' | 'integer' | 'float' | 'array' | 'object' | 'enum' | 'date' | 'url' | 'hex' | 'email' | 'any'
  required?: boolean
  message?: string
  trigger?: 'blur' | 'change'
  len?: number
  enum?: unknown[]
  validator?: (rule: any, value: any, callback: Function) => void
  min?: number
  max?: number

}

type activitykey = keyof study.Iactivity

type Iactivityrules = Partial<Record<activitykey, FormItemRule | FormItemRule[]>>

type Iteamjobkey = keyof study.Iteamjob

type Iteamjobrules = Partial<Record<Iteamjobkey, FormItemRule | FormItemRule[]>>

function time(a: string | number | Date, b: string | number | Date) {
  return (new Date(a)) < (new Date(b))
}

function timelen(a: string | number | Date, b: string | number | Date) {
  return (new Date(a)).getTime() - (new Date(b)).getTime()
}



// 比赛
export const activityrules: Iactivityrules = {
  name: [
    {
      type: 'string',
      required: true,
      trigger: 'blur',
      message: '请输入比赛名称',
    },
    {
      min: 3, message: '最少3个字符', trigger: 'blur'
    }
  ],
  signupstarttime: [
    {
      trigger: 'blur',
      message: '请选择时间',
      type: 'date'
    }
  ],
  signupendtime: [
    {
      trigger: 'blur',
      message: '请选择时间',
      validator: function (r, v, c) {
        if (!v) return c(Error('请选择时间'))
      },
    }
  ],
  type: [
    {
      type: 'enum',
      required: true,
      trigger: 'change',
      message: '请选择类型',
      enum: ['public', 'limit']
    },
  ],
  context: [
    {
      required: true,
      trigger: 'blur',
      message: '请输入内容',
    },
    {
      trigger: 'blur',
      message: '最少输入20个字符',
      min: 20
    }
  ]
}

type Iarticlerules = {
  [key in keyof study.Iarticle]: Irules[]
}

// 文章
export const articlerules: Iarticlerules = {
  name: [
    {
      type: 'string',
      required: true,
      trigger: 'blur',
      message: '请输入活动名称',
    },

    {
      min: 3, message: '最少3个字符', trigger: 'blur'
    }
  ],
  showtype: [
    {
      type: 'enum',
      required: true,
      trigger: 'change',
      message: '请选择类型',
      enum: ['0', '1', '2']
    },
  ],
  context: [
    {
      required: true,
      trigger: 'blur',
      message: '请输入内容',
    },
    {
      trigger: 'blur',
      message: '最少输入20个字符',
      min: 20
    }
  ]
}

type Iteamteskrule = {
  [key in keyof study.Iteamtask]: Irules[]
}

export const teamteskrules: Iteamteskrule = {
  user: [
    {
      type: 'array',
      required: true,
      message: '请选择成员',
      trigger: 'blur'
    }
  ],
  context: [
    {
      required: true,
      message: '请填写任务内容',
      trigger: 'blur'
    }
  ],
  info: [

  ]
}

type Iteamrules = {
  [key in keyof study.Iteam]: Irules[]
}

export const teamrules: Partial<Record<keyof study.Iteam, FormItemRule | FormItemRule[]>> = {
  name: [
    {
      required: true,
      message: '请填写团队名称',
      trigger: 'blur'
    }
  ]
}

type Iquestionrulse = {
  [key in keyof study.Iquestion]: Irules[]
}

export const questionrules: Partial<Record<keyof study.Iquestion, FormItemRule | FormItemRule[]>> = {
  name: [
    {
      required: true,
      message: '请填写题目名称',
      trigger: 'blur'
    }
  ],
  type: [
    {
      type: 'string',
      required: true,
      message: '请选择题目类型',
      trigger: 'change',
      enum: ['单选', '代码', '判断', '多选', '填空']
    }
  ],
  context: [
    {
      required: true,
      message: '请填写题目内容',
      trigger: 'blur'
    }
  ],
  difficulty: [
    {
      required: true,
      message: '请填写题目难度',
      trigger: 'blur'
    }
  ],
  range: [
    {
      type: 'string',
      required: true,
      message: '请选择题目范围',
      trigger: 'change',
      enum: ['public', 'team', 'match', 'user']
    }
  ],
  isopen: [
    {
      type: 'boolean',
      message: '请选择是否显示题目',
      trigger: 'change',
    }
  ],
}


export const teamjobrules: Iteamjobrules = {
  name: [
    {
      required: true,
      message: '名称必须填写'
    }
  ]
}